package com.kumz.SpringMVC.controller;

import com.kumz.SpringMVC.pojo.User;
import com.kumz.SpringMVC.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/admin")
public class IndexController{
    @Autowired
    private UserService userService;
    @GetMapping("/showIndex")
    public void index(){
        System.out.println("访问了index控制器showIndex方法");
    }
    @GetMapping("/html/welcome")
    public void welcome(){
        System.out.println("访问了index控制器welcome方法");
    }
    @GetMapping("/html/admin-list")
    public void adminList(Model model){
        List<User> users = userService.selectAllUser();
        model.addAttribute("list",users);
        System.out.println("调用了index控制器adminList方法");
    }
    @RequestMapping("/html/toAddUser")
    public void toAddUser(){ }

    @GetMapping("/html/admin-add")
    public String adminAdd(User user){
        userService.addUser(user);
        return "redirect:/admin/html/admin-list";
    }
    @RequestMapping("/html/toUpdateUser")
    public void toUpdateUser(){ }

    @GetMapping("/html/admin-edit")
    public String adminUpdate(User user){
        userService.addUser(user);
        return "redirect:/admin/html/admin-list";
    }
}
